package sdk.org.apache.shiro.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.titan.core.utils.data.ListUtils;
import com.titan.core.web.utils.ControllerUtils;
import com.titan.services.GenerateCode.v4.HtmlBuilderV4;
import com.titan.services.GenerateCode.v4.domain.HtmlElementProperty;
import com.titan.services.GenerateCode.v8.ViewCode.base.ViewCodeTagV8;
import com.titan.services.GenerateCode.v8.ViewXML.tags.bootstrap4.Bootstrap4BlankPageTagV8;
import com.titan.services.GenerateCode.v8.ViewXML.tags.html.HtmlTagV8;
import com.titan.services.GenerateCode.v8.ViewXML.utils.CustomUtilsV8;
import com.titan.services.GenerateCode.v8.common.utils.UtilsV8;

public class CreatePageUtils {
    public static void login(HttpServletRequest request, HttpServletResponse response) throws Exception {
        HtmlBuilderV4 builder = HtmlBuilderV4.$(request, response, "登录页面");
        builder.form(request.getContextPath()+"/login/submit", ListUtils.toList(
                HtmlElementProperty.$().setLabel("用户名").setType("text").setId("username").setName("username")
               ,HtmlElementProperty.$().setLabel("密码").setType("password").setId("password").setName("password")
               ,HtmlElementProperty.$().setType("submit").setValue("登录")
               ));
        
        /*
<div class="error">${error}</div>
<form action="" method="post">
    用户名：<input type="text" name="username" value="<shiro:principal/>"><br/>
    密码：<input type="password" name="password"><br/>
    自动登录：<input type="checkbox" name="rememberMe" value="true"><br/>
    <input type="submit" value="登录">
</form>        
        */
        builder.toHTML();
    }
    
    public static void loginSuccess(HttpServletRequest request, HttpServletResponse response, Object principal) throws Exception {
        HtmlTagV8 xml = CustomUtilsV8.html(principal+"登录成功！");
        
        Bootstrap4BlankPageTagV8 module = new Bootstrap4BlankPageTagV8();
        module.tagChild(xml);
        ViewCodeTagV8<?> tag = UtilsV8.getTag(module);
        String html = tag.codeHTML();
        ControllerUtils.writeHtml(response, html.toString());
        
        HtmlBuilderV4 builder = HtmlBuilderV4.$(request, response, "登录成功页面");
        builder.html(principal+"登录成功！");
        builder.toHTML();
    }
    
    public static void authenticated(HttpServletRequest request, HttpServletResponse response, Object principal) throws Exception {
        HtmlBuilderV4 builder = HtmlBuilderV4.$(request, response, "验证通过页面");
        builder.html(principal+"身份验证已通过。");
        builder.toHTML();
    }

    
    public static void xxxx(HttpServletRequest request, HttpServletResponse response) throws Exception {
        HtmlBuilderV4 builder = HtmlBuilderV4.$(request, response, "页面");
        builder.toHTML();
    }
}
